$(function () {
	//$("#historyGrid").jTable;
 $(document).ready(function(){
			//$("#measure-select").width(parseInt(($(window).width()-92)/212)*212);
					initTimeBox();
	             initHistoryTable();
				//$("#allowselect").tinyscrollbar();
			
			$('#measure-select').window('open');  // open a window  
            $('#measure-select').window('close');  // close a window  
            });
$.parser.onComplete(function(){
	alert("COMPLETE");
	});
					
					$(window).load(function(){
	

			$(".datagrid-body").tinyscrollbar({axis : 'x' });		
			});	
	$("#select-measure").on("click",function(){
		$(".datagrid-body").tinyscrollbar({axis : 'x' });	
		});	
		
	});
	 function initHistoryTable() {
     
          var columnsT = new Array(); //定义列集合
          var row = ["机组可控", "投入返回", "通信正常", "机组闭锁", "增磁闭锁", "减磁闭锁", "有功功率", "无功功率", "机端电压", "机端电流", "励磁电流", "视在功率", "功率因数", "厂用电压1", "厂用电压2", "厂用电压3", "厂用电压4"];
          //根据首行数据创建columns配置
          $.each(row, function (i, v) {
              if (i != "username") {
                  var column = {};
                  column["title"] = row[i]; //我这里默认用键值做title，一般可以根据键值自定义
                  column["width"] = 80;
                  column["field"] = "d_"+i; //数据的键值就是field
                  column["align"] = "center";
                  //                column["styler"] = function (value) {
                  //                    var d = new Date(sdate + '-' + i);
                  //                    if (d.getDay() == 6 || d.getDay() == 0) {
                  //                        return "background:#DDD";
                  //                    }

                  //                    if (value == 1) {
                  //                        return "background:#CCFF33";
                  //                    }

                  //                };
                  column["formatter"] = function (value) {
                      return value;
                  };
                  column["autoRowHeight"] = false;
                  column["striped"]  = true;
                  column["collapsible"]  = true;

                  columnsT.push(column); //放入定义数组
              }
          });

          //实例化一个datagrid
          $('#historyGrid').datagrid({
              
              rownumbers: true,
			  pagination:true,

              singleSelect: true,
              fit: true,
              striped: true,
              onSelect: function (rowIndex) {
                  $(this).datagrid("unselectRow", rowIndex);
              },
           //   frozenColumns: [[{
           ///       title: '机组',
           //       field: 'aaa',
           //       width: 80,
           //       align: "center"
           //   }]],
              columns: [columnsT]
          }); //.datagrid("loadData", resp.rows); //实例化之后立刻载入数据源
      }